package com.huangliusong.converter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.beans.BeanUtils;

import com.huangliusong.dataobject.OrderMaster;
import com.huangliusong.form.OrderForm;

public class OrderFormToOrderMaster {

	public static OrderMaster convert(OrderForm orderForm) {
		OrderMaster orderMaster = new OrderMaster();
		BeanUtils.copyProperties(orderForm, orderMaster);
		orderMaster.setOrderAmount(Double.parseDouble(orderForm.getOrderAmount()));
		orderMaster.setPickTime(converDate(orderForm));
		orderMaster.setGoodWeight(Double.parseDouble(orderForm.getGoodWeight()));
		return orderMaster;
	}

	private static Date converDate(OrderForm orderForm) {
		SimpleDateFormat sdf = new SimpleDateFormat(" yyyy-MM-dd HH:mm:ss ");
		Date date = null;
		try {
			date = sdf.parse(" " + orderForm.getPickTime() + " ");
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return date;
	}

	public static void main(String[] args) {
		OrderForm orderForm = new OrderForm();
		orderForm.setPickTime("2018-05-12 18:18:54");
		Date date = OrderFormToOrderMaster.converDate(orderForm);
		System.err.println(date);
	}
}
